<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.1</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="__ADMIN__/css/font.css">
    <link rel="stylesheet" href="__ADMIN__/css/xadmin.css">
    <script type="text/javascript" src="__ADMIN__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__/js/xadmin.js"></script>
    <script type="text/javascript" src="__ADMIN__/js/cookie.js"></script>
</head>
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a><cite>{$nav}</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-3" style="line-height:30px"></i></a>
    </div>
    <div class="x-body">
      <div class="layui-tab layui-tab-card">
        <ul class="layui-tab-title">
          <li class="layui-this">网站设置</li>
          <!-- <li class="">用户管理</li> -->
        </ul>
        <div class="layui-tab-content">
          <!-- 选项卡1 -->
          <div class="layui-tab-item layui-show">
            <form class="layui-form">
              {volist name="siteConfRes" id="siteconf"}
              <script>
                  layui.use('upload', function(){
                      var $ = layui.jquery
                      ,upload = layui.upload;
                      //普通图片上传
                      var uploadInst = upload.render({
                          elem: '#{$siteconf.ename}'
                          , url: '{:url("Conf/upload")}'
                          , before: function (obj) {
                            //预读本地文件示例，不支持ie8
                            obj.preview(function (index, file, result){
                                //如果有图片再点击上传就撤销原来的图片
                                var img=$("#img_{$siteconf.ename}").attr("src");
                                var imgurl=$("#value_{$siteconf.ename}").val();
                                var id=$("#value_{$siteconf.ename}").attr('conf_id');
                                if(img){
                                    $.ajax({
                                        type:"post",
                                        dataType:"json",
                                        data:{id:id,imgurl:imgurl},
                                        url:"{:url('Conf/cancel')}",
                                        success:function(data){
                                        }
                                    });
                                }
                                $('#img_{$siteconf.ename}').attr('src', result); //图片链接(base64)
                            });
                          }
                          , done: function (res) {
                              //如果上传失败
                              if (res.code == 0) {
                                  return layer.msg(res.err);
                              }
                              //上传成功
                              if(res.code == 1) {
                                  $('#value_{$siteconf.ename}').attr('value',res.savename);
                              }
                          }
                      });
                  });
                  //ajax图片撤销
                  layui.use('layer', function(){
                      var layer = layui.layer;
                      $("#cancel_{$siteconf.ename}").click(function(){
                          var img=$("#img_{$siteconf.ename}").attr("src");
                          var imgurl=$("#value_{$siteconf.ename}").val();
                          var id=$("#value_{$siteconf.ename}").attr('conf_id');
                          if(!img){
                              layer.msg('还没有上传', {icon: 2});
                              return false;
                          }
                          layer.confirm('确定要撤销吗？', {icon: 3, title:'提示'}, function(index){
                            $("#img_{$siteconf.ename}").attr("src",'');
                            $("#value_{$siteconf.ename}").val('');
                              $.ajax({
                                type:"post",
                                dataType:"json",
                                data:{imgurl:imgurl,id:id},
                                url:"{:url('Conf/cancel')}",
                                success:function(data){
                                  if(data==1){
                                      layer.msg('撤销成功', {icon: 1});
                                  }else{
                                      layer.msg('撤销失败', {icon: 2});
                                  }
                                }
                              });
                            layer.close(index);
                          });
                      });  
                  });
              </script>
              <div class="layui-form-item">
                  <label for="username" class="layui-form-label" style="width:120px;">
                      {$siteconf.cname}
                  </label>
                  <div class="layui-input-inline" style="width:40%;">
                  {switch name="$siteconf['form_type']"}

                    {case value="text"}
                      <input type="text" name="{$siteconf.ename}" value="{$siteconf.value}" required=""
                      autocomplete="off" class="layui-input">
                    {/case}

                    {case value="radio"}
                      {if condition="$siteconf['values']"}
                        {php} $arr=explode(',',$siteconf['values']);{/php}
                        {volist name="arr" id="v"}
                        <input type="radio" {if condition="$v eq $siteconf['value']"}checked{/if} name="{$siteconf.ename}" value="{$v}" title="{$v}">
                        {/volist}
                      {/if}
                    {/case}

                    {case value="checkbox"}
                      {if condition="$siteconf['values']"}
                        {php}
                        $arr_values=explode(',',$siteconf['values']);
                        $arr_value=explode(',',$siteconf['value']);
                        {/php}
                        {volist name="arr_values" id="v"}
                        <input type="checkbox" name="{$siteconf.ename}[][]" value="{$v}" {if condition="in_array($v,$arr_value)"}checked{/if}  title="{$v}" lay-skin="primary" >
                        {/volist}
                      {/if}
                    {/case}

                    {case value="select"}
                      {if condition="$siteconf['values']"}
                        {php} $arr=explode(',',$siteconf['values']);{/php}
                        <select name="{$siteconf.ename}" lay-filter="aihao">
                          {volist name="arr" id="v"}
                          <option value="{$v}" {if condition="$v eq $siteconf['value']"}selected{/if}>{$v}</option>
                          {/volist}
                        </select>
                      {/if}
                    {/case}

                    {case value="textarea"}
                      <textarea type="text" name="{$siteconf.ename}" autocomplete="off" class="layui-textarea">{$siteconf.value}</textarea>
                    {/case}

                    {case value="file"}
                      <button type="button" style="width: 70px;" class="layui-btn layui-btn-sm layui-btn-normal" id="{$siteconf.ename}"><i class="layui-icon">&#xe67c;</i>上传</button>
                      <button type="button" style="width: 70px;" class="layui-btn layui-btn-sm layui-btn-normal" id="cancel_{$siteconf.ename}"><i class="layui-icon layui-icon-refresh-3"></i>撤销</button>
                      <img class="layui-upload-img" id="img_{$siteconf.ename}" {if condition="$siteconf['value'] neq ''"}src="__UPLOADS__/conf/{$siteconf.value}"{else /}src=""{/if} width="140px" style="margin-top: 5px;display: block;">
                      <input type="hidden" name="{$siteconf.ename}" conf_id="{$siteconf.id}" id="value_{$siteconf.ename}" value="{$siteconf.value}" />
                    {/case}
                  {/switch}
                  </div>
              </div>
            {/volist}
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    确定配置
                </button>
            </div>
            
          </div>
          <!-- 选项卡2 -->
          <!-- <div class="layui-tab-item">
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add2" lay-submit="">
                    确定配置
                </button>
            </div>
            </form>
          </div> -->
        </div>
      </div>
    </div>
    <script>
        layui.use(['form','layer'], function(){
          $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;

          //监听提交
          form.on('submit(add)', function(data){
            console.log(data.field);
            $.ajax({
                type:'POST',
                dataType:'json',
                data:{data:data.field,},
                url:"{:url('Conf/conf')}",
                success:function(obj){
                  layer.msg(obj.msg, {icon: obj.icon,time:1000},function(){
                    location.reload();
                  });
                }
            });
            return false;
          });
        });
    </script>
  </body>

</html>